//
//  QZCommentShowCell.m
//  shortvideoplay
//
//  Created by tikeios_002 on 2024/6/18.
//

#import "QZCommentShowCell.h"

@implementation QZCommentShowCell
{
    UIImageView * avatar;
    UILabel * nick;
    UILabel * author;
    UILabel * comment;
    UILabel * time;
    UIButton * reply;
    UIButton * fy;
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
    [self addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = viewback_black;
        avatar = [UIImageView new];
        avatar.contentMode = UIViewContentModeScaleAspectFill;
        avatar.layer.cornerRadius = 16;
        avatar.clipsToBounds = YES;
        [self.contentView addSubview:avatar];
        
        UIButton *avatarButton = [[UIButton alloc]init];
        avatarButton.layer.cornerRadius = 16;
        [avatarButton addTarget:self action:@selector(avatarEvent) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:avatarButton];
        
        nick = [UILabel new];
        nick.textColor = ColorHex_Alpha(@"FFFFFF", 0.8);
        nick.font = Font(13);
        [self.contentView addSubview:nick];
        
        author = [UILabel new];
        author.backgroundColor = MainColor;
        author.textColor = [UIColor whiteColor];
        author.font = Font(10);
        author.layer.cornerRadius = 3;
        author.clipsToBounds = YES;
        author.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:author];
        
        comment = [UILabel new];
        comment.textColor = UIColor.whiteColor;
        comment.font = Font(14);
        comment.numberOfLines = 0;
        [self.contentView addSubview:comment];
        
        time = [UILabel new];
        time.textColor = ColorHex_Alpha(@"FFFFFF", 0.8);
        time.font = Font(12);
        [self.contentView addSubview:time];
        
        reply = [UIButton new];
        [reply setTitleColor:ColorHex_Alpha(@"FFFFFF", 0.8) forState:UIControlStateNormal];
        reply.titleLabel.font = FontBold(12);
        [reply addTarget:self action:@selector(replyTap) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:reply];
        
        fy = [UIButton new];
        [fy setTitleColor:ColorHex_Alpha(@"FFFFFF", 0.8) forState:UIControlStateNormal];
        fy.titleLabel.font = FontBold(12);
        [fy addTarget:self action:@selector(fyTap) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:fy];
        
        [reply setTitle:@"回复" forState:UIControlStateNormal];
        [fy setTitle:@"翻译" forState:UIControlStateNormal];
        author.text = @"作者";
        
        [avatar mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.top.mas_offset(12);
            make.width.height.mas_offset(32);
        }];
        [avatarButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.top.mas_offset(12);
            make.width.height.mas_offset(32);
        }];
        [nick mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(avatar.mas_right).mas_offset(10);
            make.top.mas_offset(15);
            make.height.mas_offset(16);
        }];
        [author mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(nick.mas_right).mas_offset(3);
            make.top.mas_offset(15);
            make.right.mas_lessThanOrEqualTo(-12);
            make.width.mas_offset(24);
            make.height.mas_offset(16);
        }];
        
        [comment mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(avatar.mas_right).mas_offset(10);
            make.top.equalTo(nick.mas_bottom).mas_offset(3);
            make.right.mas_offset(15);
        }];
        [time mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(avatar.mas_right).mas_offset(10);
            make.top.equalTo(comment.mas_bottom).mas_offset(5);
            make.height.mas_offset(16);
            make.bottom.mas_offset(-10);
        }];
        [reply mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(time.mas_right).mas_offset(12);
            make.top.equalTo(comment.mas_bottom).mas_offset(5);
            make.height.mas_offset(16);
            make.width.mas_offset(44);
        }];
        [fy mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(reply.mas_right).mas_offset(12);
            make.top.equalTo(comment.mas_bottom).mas_offset(5);
            make.right.mas_lessThanOrEqualTo(115);
            make.height.mas_offset(16);
            make.width.mas_offset(44);
        }];
    UIButton * textShowButtonTo1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        NSString * textShowButtonTitleTo1 = @"测试功能";
        [textShowButtonTo1 setTitle:textShowButtonTitleTo1 forState:UIControlStateNormal];
        NSInteger textShowArcTo1 = arc4random_uniform(22);
        NSLog(@"随机数：%ld", (long)textShowArcTo1);
    }
    return self;
}
- (void)setCommentModel:(QZCommentModel *)commentModel{
    _commentModel = commentModel;
    [avatar sd_setImageWithURL:KUrlString(commentModel.face) placeholderImage:KImageNamed(@"ic_head_defuls")];
    nick.text = commentModel.nickname;
    if([commentModel.mid intValue] == [commentModel.fmid intValue]){
        [author mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_offset(24);
        }];
    }else{
        [author mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_offset(0);
        }];
    }
    comment.text = commentModel.contents;
    time.text = commentModel.timestr;
}
- (void)replyTap{
    self.commenReplyTapBlock(0);
}
- (void)fyTap{
    self.commenReplyTapBlock(1);
}
- (void)avatarEvent{
    self.commenReplyTapBlock(2);
}
@end
